package com.chencs.biz.category.service;

import com.alibaba.fastjson.JSON;
import com.chencs.vo.biz.category.CategoryItemModel;
import com.chencs.vo.biz.category.CategoryModel;
import com.chencs.webmvc.rest.RestFullTemplate;
import com.qiniu.util.Json;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by fangzehua on 2017/7/4.
 */
@Service
public class CategoryService {
    private static final Logger logger = LoggerFactory.getLogger(CategoryService.class.getName());

    @Autowired
    RestFullTemplate restTemplate;
    /**标志远程服务url**/
    private static final String URLPATH = "service-common/category/";

    public String categoryList() throws Exception{
        String ret = restTemplate.postForObject(URLPATH + "getCategoryList", String.class,"");
        logger.info("CategoryService getCategoryList zuulGateWay result {}", ret);
        return ret;

    }

    public String findCategoryById(String cid) throws Exception{
        String ret = restTemplate.postForObject(URLPATH + "findCategoryById", String.class,cid);
        logger.info("CategoryService findCategoryById zuulGateWay result {}", ret);
        return ret;
    }

    public String updateCategory(CategoryModel model) throws Exception{
        String ret = restTemplate.postForObject(URLPATH + "updateCategory", String.class,model);
        logger.info("CategoryService updateCategory zuulGateWay result {}", ret);
        return ret;
    }

    public String getCategoryItemByCid(String cid) throws Exception{
        String ret = restTemplate.postForObject(URLPATH + "getCategoryItemByCid", String.class,cid);
        logger.info("CategoryService getCategoryItemByCid zuulGateWay result {}", ret);
        return ret;
    }


    public String saveCategory(CategoryModel model) throws Exception{
        String ret = restTemplate.postForObject(URLPATH + "insertCategory", String.class,model);
        logger.info("CategoryService insertCategory zuulGateWay result {}", ret);
        return ret;
    }



    public String getTaoBaoCategoryList() throws Exception{
        String ret = restTemplate.postForObject(URLPATH + "getTaoBaoCategoryList", String.class,"");
        logger.info("CategoryService getTaoBaoCategoryList zuulGateWay result {}", ret);
        return ret;
    }

    public String delTaoCategory(String id) throws Exception{
        String ret = restTemplate.postForObject(URLPATH + "delTaoBaoCategoryById", String.class,id);
        logger.info("CategoryService delTaoBaoCategoryById zuulGateWay result {}", ret);
        return ret;

    }


    public String insertCategoryItem(CategoryItemModel model) throws Exception{
        String ret = restTemplate.postForObject(URLPATH + "insertCategoryItem", String.class,model);
        logger.info("insertCategoryItem delTaoBaoCategoryById zuulGateWay result {}", ret);
        return ret;

    }


    public String updateCategoryItem(CategoryItemModel model) throws Exception{
        System.out.println(JSON.toJSON(model));
        String ret = restTemplate.postForObject(URLPATH + "updateCategoryItem", String.class,model);
        logger.info("CategoryService updateCategoryItem zuulGateWay result {}", ret);
        return ret;
    }

    public String findCategoryItemModelById(String id) throws Exception{
        String ret = restTemplate.postForObject(URLPATH + "findCategoryItemModelById", String.class,id);
        logger.info("CategoryService findCategoryItemModelById zuulGateWay result {}", ret);
        return ret;
    }




}
